import { ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router";

export const usePersonalCenterHooks = () => {
  const route = useRoute();
  const router = useRouter();

  // 监听当前路由变化修改currComName
  const currComName = ref<any>("");
  watch(
    () => route?.query.name,
    (newVal, oldVal) => {
      currComName.value = newVal || "info";
    },
    { immediate: true }
  );

  const handleBarClick = (name: string) => {
    router.replace({ path: "/personalCenter", query: { name }, replace: true });
  };

  return { currComName, handleBarClick };
};
